package com.ringtheweb.common.util;

import java.util.Collection;

/**
 * Encapsulation of logic operations on different types of objects
 * @author ldewavri
 *
 */
public class Logic {
	public static boolean areEmpty(Collection<?>... cs) {
		if (isNull(cs)) { return true; }
		if ( cs.length == 0 ) { return true; }
		
		for(Collection<?> c : cs) { if (notEmpty(c)) return false; }
		return true;
	}

	public static boolean hasOnlyOneElement(Collection <?>c ) {
		return notEmpty(c) && c.size() == 1;
	}
	
	public static boolean hasAtLeastOneElement(Collection <?>c ) {
		return notEmpty(c) && c.size() >= 1;
	}

	public static boolean implies(boolean p, boolean q) {
		return !p || q;
	}

	public static boolean isEmpty(Collection<?> c) {
		return !notEmpty(c);
	}
	
	public static boolean isInstanceOf(Class<?> type, Object obj) {
        Assert.notNull(type, "Type to check against must not be null");
        return type.isInstance(obj);
    }
	
	public static boolean isNotNull(Object o) {
		return o != null;
	}
	
	public static boolean isNull(Object o) {
		return o == null;
	}
	
	public static boolean isTrue(boolean expression) {
		return expression == true;
	}
	
	public static boolean not(boolean expression) {
		return !expression;
	}
	
    public static boolean notEmpty(Collection<?> c) {
		return implies(isNotNull(c) , not(c.isEmpty()));
	}


}
